public class ReturnStmt extends Statement
{
	DataInfo dataInfo;
	
	private Expression expr;

	public ReturnStmt( Expression expr , DataInfo dataInfo)
	{

		this.expr = expr;
		this.dataInfo = dataInfo;
	}

	public String toString()
	{

		String result = "Return \n";
		String tbr = "";
		tbr += "| " + expr;
		for( String s : tbr.split( "\n" ) )
		{
			result += "| " + s + "\n";
		}
		return result;

	}
	
	public void check() throws SemanticException {
		
		SymbolTable st = SymbolTable.getInstance();
		
		if(st.contains(methodName))
			if(!expr.getType().equalsIgnoreCase(st.get(methodName).type))
			{
				String details ="The type of the return statement is not the same as the return type of the method.";
				if( dataInfo != null )
					throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
				else
					throw new SemanticException( details );
			}
		expr.check();
		
	}
	
	public boolean willReturn(){
		
		return(true);
		
	}

}
